package com.ct;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

@SpringBootApplication
@Slf4j
public class StudyDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(StudyDemoApplication.class, args);
    }

    @Autowired
    private Environment env;

    @Bean
    public CommandLineRunner commandLineRunner() {
        return (args) -> {
            // 获取CPU核心数
            int availableProcessors = Runtime.getRuntime().availableProcessors();
            log.info("CPU核心数: " + availableProcessors);
            // 获取JVM当前活动线程数
            int activeThreads = Thread.activeCount();
            log.info("当前活动线程数: " + activeThreads);
            //本地主机的地址
            InetAddress inetAddress = InetAddress.getLocalHost();
            // 你也可以通过env获取其他配置信息
            //String someConfig = env.getProperty("some.config.key", "默认值");
            //System.out.println("配置信息: " + someConfig);
//            log.info(AnsiOutput.toString(AnsiColor.BRIGHT_GREEN, StrUtil.format("项目名称spring.application.name:{}", env.getProperty("spring.application.name"))));
//            log.info(AnsiOutput.toString(AnsiColor.BRIGHT_GREEN, StrUtil.format("项目请求地址:{}:{}",inetAddress.getHostAddress(),env.getProperty("server.port"))));
//            log.info(AnsiOutput.toString(AnsiColor.BRIGHT_GREEN, "project server has started successfully!"));
            log.info(StrUtil.format("项目名称[spring.application.name]:{}", env.getProperty("spring.application.name")));
            log.info(StrUtil.format("项目请求地址:{}:{}",inetAddress.getHostAddress(),env.getProperty("server.port")));
            log.info( "project server has started successfully!");
        };
    }

}
